package com.imti.mall.order.controller;

import com.imti.mall.common.Api.CommonResult;
import com.imti.mall.model.oms.pojo.OmsOrderReturnReason;
import com.imti.mall.model.oms.query.OmsOrderListParam;
import com.imti.mall.order.service.OrderReturnReasonService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags="订单管理")
@RequestMapping("/api/v1/orders")
public class OrderReturnReasonController {
    @Resource
    private OrderReturnReasonService returnReasonService;
    @GetMapping("/returnReason")
    public CommonResult fetchReturnReasonList(OmsOrderListParam listParam){
        listParam.setPageIndex();
        List<OmsOrderReturnReason> returnReasonList= returnReasonService.fetchReturnReasonList(listParam);

        return CommonResult.success(returnReasonList);
    }

    @PostMapping ("/returnReason/delete")
    public CommonResult deleteReturnReason(Integer[] ids){

       int n= returnReasonService.deleteReturnReason(ids);

        return CommonResult.success(n>0);
    }

    @PostMapping ("/returnReason//update/status")
    public CommonResult updateReturnReasonStatus(Integer ids,Integer status){
        Map<String,Object> map=new HashMap<>();
          map.put("ids",ids);
          map.put("status",status);
        int n= returnReasonService.updateReasonStatus(map);

        return CommonResult.success(n>0);
    }


    @PostMapping ("/returnReason/create")
    public CommonResult addReturnReason(OmsOrderReturnReason returnReason){

        int n= returnReasonService.addReturnReason(returnReason);

        return CommonResult.success(n>0);
    }

    @GetMapping ("/returnReason/{id}")
    public CommonResult getReasonDetail(@PathVariable Integer id){
        OmsOrderReturnReason reasonDetail = returnReasonService.getReasonDetail(id);

        return CommonResult.success(reasonDetail);
    }

    @PostMapping ("/returnReason/update")
    public CommonResult updateReturnReason(@RequestBody OmsOrderReturnReason returnReason){

        int n= returnReasonService.updateReturnReason(returnReason);

        return CommonResult.success(n>0);
    }

}
